package com.caac.core.dm;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import com.caac.core.config.ActionConf;
import com.caac.core.config.Config;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright AgileCentury 2006</p>
 * <p>Company: AgileCentury</p>
 * @author <a href="mailto:project@agilecentury.com">Project Group</a>
 * @version 1.0
 */

public class NormalUser extends User {
	private static final long serialVersionUID = 1L;
    private Set roles = new HashSet();

    public Set getRoles() {
        return roles;
    }

    public void setRoles(Set roles) {
        this.roles = roles;
    }

    public void addRole(Role role) {
        roles.add(role);
    }

    protected boolean isAccessible(ActionConf actionConf) {
        for (Iterator it = roles.iterator(); it.hasNext(); ) {
            Role role = (Role) it.next();
            if (Config.getInstance().getRolePermissions().getChild(role.
                    getId() + actionConf.getKey()) != null) {
                return true;
            }
        }
        return true;
    }
    public String getRoleName() {
        String roleName = "";
        try {
            for (Iterator it = roles.iterator();it.hasNext(); ) {
                Role role = (Role) it.next();
                if ("".equals(roleName)) {
                    roleName = role.getRoleName();
                } else {
                    roleName = roleName + "," + role.getRoleName();
                }
            }
        } catch (Exception e) {
        }
        return roleName;
    }
    
    public String getRoleNotes() {
        String roleName = "";
        try {
            for (Iterator it = roles.iterator();it.hasNext(); ) {
                Role role = (Role) it.next();
                //if ("".equals(roleName)) {
                //    roleName = role.getNotes();
                //} else {
                    roleName = roleName + "," + role.getNotes();
                //}
            }
        } catch (Exception e) {
        }
        return roleName;
    }
}
